$(function () {
    $(".ordinaryFast").Validform({
        btnSubmit: "#sure_btn",
        showAllError: true,
        tiptype: 3
    });
    $('.btn').click(function () {//明码密码切换
        var _that = $(this);
        var password_type = $(this).siblings('input').attr('type');
        if (password_type == 'password') {
            _that.siblings('input').attr('type', 'text');
            _that.children('img').attr('src', 'https://file.viplgw.cn/ui/thinku-ielts-new/images/newLogin/isHide.png');

        } else if (password_type == 'text') {
            _that.siblings('input').attr('type', 'password');
            _that.children('img').attr('src', 'https://file.viplgw.cn/ui/thinku-ielts-new/images/newLogin/isShow.png');

        }
    })
});

//确定
function sureSub() {
    var userPass = $('.userPass').val();
    var userName = $('.userName').val();
    var verificationCode = $('.loginCode').val();
    if (verificationCode == "") {
        return false;
    }
    if (userName == "") {
        return false;
    }
    if (userPass == "") {
        return false;
    }
    $.post('/cn/new-api/change-password', {
        passowrd: userPass,
        phone: userName,
        phonecode: verificationCode
    }, function (re) {
        if (re.code == 1) {
            alert('找回密码成功');
            window.location.href = '/login.html';
        } else {
            alert(re.message);
        }
    }, 'json')
}

//enter确定
function enterModify() {
    if (event.keyCode == 13) {
        sureSub();
    }
}

//监听
function watch() {
    if ($('.userName').val().length == 11) {
        $('.phoneCode').removeAttr('disabled');
        $('.phoneCode').addClass('phoneCodeVi');
    } else {
        $('.phoneCode').attr('disabled', true);
        $('.phoneCode').removeClass('phoneCodeVi');
    }
}

//发送验证码
function sendCode(obj) {
    var timeNum = 60;
    var phone = $('.userName').val();

    //type  1--注册  9--绑定  2--找回
    $.post('/cn/new-api/phone-code', {phoneNum: phone, type: 2}, function (re) {
        alert(re.message);
        if (re.code == 1) {
            $('.userName').attr('readonly', true);
            $(obj).attr('disabled', true);
            $(obj).removeClass('phoneCodeVi');
            $(obj).addClass('phoneCodeSi');
            var timer = setInterval(function () {
                $(obj).html("重新获取(" + (timeNum + 'S)'));
                timeNum--;
                if (timeNum < 0) {
                    clearInterval(timer);
                    $('.userName').removeAttr('readonly');
                    $(obj).removeAttr('disabled');
                    $(obj).addClass('phoneCodeVi');
                    $(obj).removeClass('phoneCodeSi');
                    $(obj).html("获取短信验证码");
                }
            }, 1000);
        }

    }, 'json');
}
